﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SixApp.Extensions
{
    public static class FormExtensions
    {
        public static void ShowMdiChild<T>(this Form mdiParent, string mdiChildName) where T : Form, new()
        {
            if (mdiParent.IsMdiContainer)
            {
                var mdiChild = mdiParent.MdiChildren.FirstOrDefault(i => i.Name.Equals(mdiChildName, StringComparison.OrdinalIgnoreCase));

                if (null == mdiChild)
                {
                    mdiChild = new T();
                    mdiChild.MdiParent = mdiParent;
                }

                mdiChild.Show();
                mdiChild.BringToFront();
            }                        
        }
    }
}
